package com.huyna.docbao.Adapter;

import java.util.ArrayList;
import com.huyna.docbao.R;
import com.huyna.docbao.model.RowItem;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListItemAdapter extends BaseAdapter{
    Context context;
    ArrayList<RowItem> lstItem;
    
    public ListItemAdapter(Context c, ArrayList<RowItem> list) {
        context = c;
        lstItem = list;
    }
    
    @Override
    public int getCount() {
        return lstItem.size();
    }

    @Override
    public Object getItem(int position) {
        return lstItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return lstItem.indexOf(getItem(position));
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater)context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.list_item, null);
        }
        ImageView image = (ImageView)convertView.findViewById(R.id.icon);
        TextView text = (TextView)convertView.findViewById(R.id.title);
        
        image.setImageResource(lstItem.get(position).getIcon());
        text.setText(lstItem.get(position).getTitle());
        
        return convertView;
    }

}
